// 如果要运行 mini-react 把这些内容复制到 src/index.js
import React from './index.js'
const element = React.createElement(
	'div',
	{
		id: 'food',
	},
	React.createElement('a', { href: 'https://www.baidu.com' }, '百度一下')
)
const TestFuncCounter = () => {
	const [state, setState] = React.useState(0)
	// console.log('state :>>', state)
	const element = React.createElement(
		'div',
		{},
		React.createElement('span', {}, `Count ${state}`),
		React.createElement(
			'button',
			{
				onClick: () => {
					setState((count) => count + 1)
				},
			},
			'+1'
		)
	)
	return element
}
class TestClassComponent extends React.Component {
	render() {
		return element
	}
}
const funcComponent = React.createElement(TestFuncCounter, {})
const classComponent = React.createElement(TestClassComponent, {})
const container = document.getElementById('root')
// 渲染
React.render(classComponent, container)

const render = (value) => {
	const onInput = (e) => {
		render(e.target.value)
	}
	const element = React.createElement(
		'div',
		{},
		React.createElement('input', {
			value,
			onInput,
		}),
		React.createElement('span', {}, `hello ${value}`)
	)
	React.render(element, container)
}
// 协调
// render('word')
